// 懒加载组件
Component({
  properties: {
    animation: { // 内置8种运动效果 fadeInUp bounceInRight bounceInUp fadeIn fadeInBottomRight flipInX lightSpeedInRight jackInTheBox
      type: String,
      value: 'fadeInUp'
    },
  },
  data: {
    id: 1
  },
  lifetimes: {
    attached() {
      const id = (Math.random() + '').replace('\.', '')
      this.setData({ id }, () => {
        const observer = this.createIntersectionObserver()
        observer.relativeToViewport()
          .observe(`.lazyload-${id}`, res => {
            if (res.intersectionRatio > 0) {
              this.setData({ id: 0 })
              this.triggerEvent('visible', true)
              observer.disconnect()
            }
          })
      })
    },
  },
  methods: {
    lazyAniEnd(e){
      this.triggerEvent('lazyAniEnd', e);
    }
  }
})
